package cn.sjtu.syo.consumer.service;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author syo 2319615164@qq.com
 * @description
 * @date 2024/9/25
 * @Copyright syo
 */
@Component
public class MQListenerService {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue1"),
            exchange = @Exchange(name = "topic.exchange", type = ExchangeTypes.TOPIC),
            key = {"china.#"}
    ))
    public void listenToQueue1(String msg) throws InterruptedException {
        System.out.println("=============> 消费者1：接收到消息：" + msg );
        Thread.sleep(20);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "topic.queue2"),
            exchange = @Exchange(name = "topic.exchange", type = ExchangeTypes.TOPIC),
            key = {"japan.#"}
    ))
    public void listenToQueue2(String msg) throws InterruptedException {
        System.out.println("====> 消费者2：接收到消息：" + msg );
        Thread.sleep(20);
    }
}
